<!DOCTYPE html>
<html lang="en">
<style>
    body {
        background-image:url("../bootstrap/imgs/2.jpg");
        background-size: cover;
    }
    #form-login {
        display: flex;
        height: 100vh;
        justify-content: center;
        align-items: center;
    }
</style>
<head>
    <meta charset="UTF-8">
    <title>注册系统</title>

    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" >
    <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
    <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap-theme.min.css">

</head>

<form  id="form-login"class="text-center">
    <div style="width: 500px">
        <div class="panel panel-info">
            <div class="panel-heading">
                <h1>欢 迎 注 册</h1>
            </div>
            <label class="sr-only" >用户名</label>
            <input type="text" id="username" name="username" class="form-control" placeholder="Username" >

            <label class="sr-only" >密码</label>
            <input type="password"id="password" name="password" class="form-control" placeholder="Password" >

            <select id="type"name="type" class="selectpicker show-tick form-control"title="Type">
                <option  hidden>Type</option>
                　<option value="0">医生</option>
                　<option value="1">挂号管理员</option>
                <option value="2">药房管理员</option>
            </select>

            <button class="btn btn-lg btn-primary btn-block" type="button" id="btn-reg">注册</button>
        </div>
    </div>
</form>

<script type="text/javascript">
    $("#btn-reg").click(function() {
        // alert("准备注册！");
        $.ajax({
            "url":"/users/reg",
            "data":{
                username:$('input[name="username"]').val(),
                password:$('input[name="password"]').val(),
                type:$("#type option:selected").val(),
            },
            "type":"post",
            "dataType":"json",
            "success":function (data) {
                console.log(data);
                if (data.state == 2002) {
                    alert("注册失败："+data.message);
                    location.href ="register.html";
                } else {
                    alert("注册成功：");
                    location.href="login.html";
                }
            }
        });
    });
</script>

</body>
</html>
